package model.searchers;
/**
 * Class URLList represents a linked list of URLs including a number of occcurrences. 
 * It is used to represent the URLs on which a given search word occurs and how many time the word occurs on each URL.
 */
public class URLList extends model.searchers.linkedListSearcher.LinkedList

{
	private int occurrences;

	/**
	 * Constructor of URLList. Initializes the list with occurrences equal to 1
	 * 
	 * @param value 	a string containing a URL
	 * @param next		the next element in the list
	 */
	public URLList(String value, URLList next) {
		super(value, next);
		occurrences = 1;
	}

	/**
	 * Constructor of URLList. Initializes the list with the specified number of occurrences
	 * 
	 * @param value 		a string containing a URL
	 * @param occurrences 	number of occurrences
	 * @param next			the next element in the list
	 */
	public URLList(String value, int occurrences, URLList next) {
		super(value, next);
		this.occurrences = occurrences;
	}
	
	/**
	 * Get the number of occurrences
	 * 
	 * @return	the number of occurrences
	 */
	public int getOccurrences() {
		return occurrences;
	}

	/**
	 * Set the number of occurrences to the specified number
	 * 
	 * @param occurrences	new number of occurrences
	 */
	public void setOccurrences(int occurrences) {
		this.occurrences = occurrences;
	}

	/**
	 * Increase the number of occurrences by one
	 */
	public void increaseOccurences() {
		occurrences++;
	}

	/**
	 * Create a copy of the URLList
	 */
	@Override
	public URLList clone() {
		URLList temp = new URLList(this.getValue(), null);
		temp.setOccurrences(this.getOccurrences());
		URLList startOfNewCopy = temp;
		URLList copyOfNextElement = null;

		URLList next = (URLList) this.getNext();

		while (next != null) {
			copyOfNextElement = new URLList(next.getValue(), null);
			copyOfNextElement.setOccurrences(next.getOccurrences());

			temp.setNext(copyOfNextElement);
			temp = (URLList) temp.getNext();
			next = (URLList) next.getNext();
		}

		return startOfNewCopy;
	}

}
